package com.visionblue.business.ship.page.collection.record

import android.os.Bundle
import android.view.View
import androidx.lifecycle.Observer
import com.visionblue.business.ship.R
import com.visionblue.business.ship.model.enums.RecordMode
import com.visionblue.business.ship.model.repository.db.CollectionRecord
import com.visionblue.business.ship.page.collection.CollectionActivity
import com.visionblue.business.ship.page.collection.WorkStatus
import com.visionblue.business.ship.util.ext.setVisible
import kotlinx.android.synthetic.main.frag_record.*
import kotlinx.coroutines.launch

/**
 * @author: xlh
 * @date: 2020-06-03 3:22 PM
 * @desc:
 */
class CheckRecordFragment : RecordFragment() {

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
//        ivOp.visibility = View.INVISIBLE
        btnCheck.setVisible(true)
        btnCheck.setText(R.string.complete_check)
        mAdapter.mode = RecordMode.CHECK_MODE
        btnCheck.setOnClickListener {
            mViewModel.inCheckMode.value = false
            launch {
                mViewModel.updateAfterChecked(mAdapter.infos).join()
                (activity as CollectionActivity?)?.changeRecordMode(RecordMode.TEXT_MODE)
            }
        }
        btnComplete.setVisible(false)
    }

    override fun onRecordsUpdate(records: MutableList<CollectionRecord>) {
        if (records.isEmpty()) {
            mAdapter.showEmpty()
        } else {
            mAdapter.infos = records
        }
    }

//    override fun showFlowBeforeWorkView() {
//        super.showFlowBeforeWorkView()
//    }

//    override fun showWeightBeforeWorkView() {
//        super.showWeightBeforeWorkView()

//    }

    // ！！！！该行代码不能被注释
    override fun onWorkStateUpdate(it: WorkStatus?) {

    }
//    override fun showFlowFinishedView() {
//
//    }

    companion object {
        fun newInstance(): CheckRecordFragment {
            return CheckRecordFragment()
        }
    }
}